<template>
    <view class="wrap">
        <u-form :model="form" ref="uForm">
            <u-form-item label="竞赛名称" label-position="top">
                <u-input v-model="value1.label" type="select" @click="select1 = true" />
                <u-select v-model="select1" :list="cpms" value-name="id" @confirm="confirm1" label-name="cName"></u-select>
            </u-form-item>
            <u-form-item label="竞赛科目" label-position="top" v-if="value1.value">
                <u-input v-model="value2" type="select" @click="select2 = true" />
                <u-select v-model="select2" :list="subs" @confirm="confirm2"></u-select>
            </u-form-item>
            <u-form-item label="人员" label-position="top">
                <u-input v-model="value3.label" type="select" @click="select3 = true" />
                <u-select v-model="select3" @confirm="confirm3" :list="ps"></u-select>
            </u-form-item>
            <u-form-item label="成绩"><u-number-box v-model="value"></u-number-box></u-form-item>
        </u-form>
        <view class="u-m-t-20">
            <u-row gutter="16" justify="center">
                <u-col span="10"><u-button type="primary" @click="saveData()" :ripple="true">保存</u-button></u-col>
            </u-row>
        </view>
    </view>
</template>

<script>
export default {
    data() {
        return {
            form:{},
            selectid: '',
            value1: {
                label: ''
            },
            value2: '',
            value3: {
                label: ''
            },
            phone: '',
            value: 0,
            select1: false,
            select2: false,
            select3: false,
            cpms: [],
            subs: [],
            ps: []
        }
    },
    onLoad() {
        this.$u.get('/apps/ssCompetitionEntity/all', {}).then(res => {
            if (res) {
                this.cpms = res
            }
        })
    },
    methods: {
        confirm1(e) {
            e.map((val, index) => {
                this.value1 = {
                    value: val.value,
                    label: val.label
                }
            })
            this.load2(this.value1.value)
        },
        confirm2(e) {
            e.map((val, index) => {
                this.value2 = val.value
            })
            this.load3()
        },
        confirm3(e) {
            e.map((val, index) => {
                this.value3.label = val.label
                this.value3.value = val.value
            })
        },
        load2(id) {
            this.selectid = id
            this.subs = []
            this.cpms.forEach(v => {
                if (id === v.id) {
                    JSON.parse(v.cSubject).forEach(v => {
                        this.subs.push({
                            value: v,
                            label: v
                        })
                    })
                }
            })
        },
        load3() {
            this.$u.get('/apps/ssResultsEntity/where', { idCompettion: this.selectid }).then(res => {
                this.ps = []
                res.forEach(v => {
                    this.ps.push({
                        value: v.sysUserEntity.id,
                        label: v.sysUserEntity.name
                    })
                })
            })
        },
        saveData() {
            console.log(this.value3)
            this.$u.post('/apps/ssResultsEntity/upr', { id: this.selectid, userid: this.value3.value, up: this.value }).then(res => {
                this.ps = []
                res.forEach(v => {
                    this.ps.push({
                        value: v.sysUserEntity.id,
                        label: v.sysUserEntity.name
                    })
                })
            })
            this.$u.route({
                type: 'redirect',
                url: 'pages/results/results_list'
            })
        }
    }
}
</script>

<style lang="less" scoped>
.wrap {
    padding: 24rpx;
}
.wrap1 {
    padding: 13rpx;
}
.ll {
    margin-right: 10rpx;
    margin-bottom: 4rpx;
}
</style>
